package test.flow;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import test.dto.CommonRspDTO;
import test.dto.UserDTO;
import test.rsp.BaseRspDTO;
import test.tradeflow.EcnyTradeContext;
import test.tradeflow.EcnyTradeFlowBuilder;
import test.tradeflow.TradeContext;
import test.tradeflow.TradeFlow;

/**
 * Created with IntelliJ IDEA.
 *
 * @ project name : example
 * @ Author: XuLeHuang
 * @ Date: 2023/1/8 13:14
 * @ Description:
 */
@Configuration
@Slf4j
public class UserQueryFlow {
    public static final String TRADE_FLOW = "UserQueryFlow";

    /**
     * 关闭订单
     *
     * @return
     */
    @Bean(name = TRADE_FLOW)
    public TradeFlow UserQueryFlow() {
        return EcnyTradeFlowBuilder.get()
                .process(this::init)
                .process(this::check)
                .process(this::response)
                .errHandler(this::tradeErrHandler)
                .build();
    }

    private void init(TradeContext<?, ?> tradeContext) {

    }

    private void check(TradeContext<?, ?> tradeContext) {

    }

    private void response(TradeContext<?, ?> tradeContext) {
        UserDTO reqMsg = (UserDTO)EcnyTradeContext.getReqMsg(tradeContext);
        log.info("DTO数据->{}" , reqMsg);
        CommonRspDTO commonRspDTO = new CommonRspDTO();
        commonRspDTO.setRetCode("PR00");
        commonRspDTO.setRetInfo("SUCCESS");
        commonRspDTO.setData(reqMsg);
        EcnyTradeContext.setRspMsg(tradeContext , commonRspDTO);
    }

    private void tradeErrHandler(TradeContext<?,?> tradeContext, Throwable throwable) {
    }

}
